// ajax 请求后端加载: 1. 用户登录数据  2. 热门车辆数据

//加载首页数据
loadInitData();

function loadInitData(){

    var token = localStorage.getItem("token");

    console.log("token-----:"+token)

    $.ajax({
        type: "get",
        url: "loadIndexData",
        headers: {"token": token},
        success: function (result) {
            console.log(result);
            var loginUser = result.data.loginCustomer;
            var carList = result.data.carList;

            if(loginUser != null) {
                $(".head-color").text(loginUser.custName);
                $(".head-color").attr("href", "customer/getId/" + loginUser.custId);
            }else{

                    $(".head-color").text("登录");
                    $(".head-color").attr("href", "login/login.jsp");
            }


            $(".hot-all").html("");
            for(var i=0;i<carList.length;i++){
                var carImg = carList[i].other1;
                var carName = carList[i].carName
                var url = "car/"+ carList[i].carId;// car/101

                var hotCarElement =  '  <div class="pho-max">\n' +
                    '            <a href="'+url+'" class="car_img"> <img class="pho-type" src="'+carImg+'"> </a>\n' +
                    '            <a href="'+url+'" class="car_name">  '+carName +' </a>\n' +
                    '         </div>';

                $(".hot-all").append(hotCarElement);
            }



        }
    })
}

